package com.example.config;

import com.alibaba.ttl.threadpool.TtlExecutors;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 线程池配置
 * @author long
 * @date 2024/8/21 20:06
 */
@Configuration
public class TaskExecutorConfig{

    @Bean
    public Executor testTaskExecutor(){
        ThreadPoolExecutor executor = new ThreadPoolExecutor(5,5,60,
                TimeUnit.SECONDS,new ArrayBlockingQueue<>(100));
        // 预启动所有核心线程
        executor.prestartAllCoreThreads();
        return TtlExecutors.getTtlExecutor(executor);
    }

    @Bean
    public Executor firstTaskExecutor(){
        return new ThreadPoolExecutor(5,5,60,
                TimeUnit.SECONDS,new ArrayBlockingQueue<>(100));
    }


}
